package com.gxa.interceptor;

//import com.gxa.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截到controller的请求 从网关来的必然带来token
 * 这里进行更进一步的校验 校验通过 在放请求到controller
 * config.FeignConfig
 */
@Component
public class TokenInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        System.out.println("token------------->" + token );

        //从token中解析出用户信息，查询数据库获取用户其他信息
//        User user = new User();
//        user.setId(10L);
//        user.setUsername("aa");
//        user.setPassword("bb");

        //把用户放入当前线程
//        UserThreadLocal.set(user);

        return true;
    }
}